package com.wondertek.liveroom;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.jasontools.data.ImageMessage;
import com.jasontools.utils.NicknameUtil;
import com.jasontools.utils.RoundedImage;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyChatOccupantsListViewAdapter extends BaseAdapter {

	private Context context = null;
	private LayoutInflater inflater = null;
	private List<String> listData = null;
	private static final int IMAGE_AVATAR = R.drawable.user_default_avatar;
	private static final int [] ImageResources = {
		R.drawable.bg_channel_1, R.drawable.bg_channel_2,
		R.drawable.bg_channel_3, R.drawable.bg_channel_4,
		R.drawable.bg_channel_5,
	};
	
	public MyChatOccupantsListViewAdapter(Context context, List<String> list) {
		this.context = context;
		this.listData = list;
		this.inflater = LayoutInflater.from(context);
	}

	public void setData(List<String> list) {
		this.listData = list;
	}
	
	@Override
	public int getCount() {
		return listData.size();
	}

	@Override
	public Object getItem(int position) {
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_find_mine_listview, null);
			holder = new ViewHolder();
			holder.ivIcon = (ImageView) convertView.findViewById(R.id.iv_item_find_mine_avatar);
			holder.tvName = (TextView) convertView.findViewById(R.id.tv_item_find_mine_name);
			holder.tvContent = (TextView) convertView.findViewById(R.id.tv_item_find_mine_content);
			holder.tvDate = (TextView) convertView.findViewById(R.id.tv_item_find_mine_date);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		//holder.ivIcon.setBackgroundResource(ImageResources[position%5]);
		BitmapDrawable drawable = (BitmapDrawable) context.getResources().getDrawable(IMAGE_AVATAR);
		holder.ivIcon.setBackgroundDrawable(new BitmapDrawable(RoundedImage.TranslateToRoundCornerImage(drawable.getBitmap(), 30)));
		holder.tvName.setVisibility(View.GONE);
		holder.tvContent.setText(NicknameUtil.getNicknameFromFullJid(listData.get(position)));
		holder.tvDate.setVisibility(View.GONE);;
		return convertView;
	}
	
	private class ViewHolder {
		public ImageView ivIcon;
		public TextView tvName;
		public TextView tvContent;
		public TextView tvDate;
	}
}
